#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int d[6] = {3, 1, 2, 1, 0, 1};
int p[6];
int a[25];
bool check() {
  rep(i, 0, 5) if (p[i] < d[i]) return false;
  return true;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    rep(i, 1, n) cin >> a[i];
    rep(i, 0, 5) p[i] = 0;
    int i = 1;
    while (i <= n) {
      if (a[i] <= 5) {
        p[a[i]]++;
        if (check()) break;
      }
      i++;
    }
    if (i <= n)
      cout << i << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}